<?php

namespace SunAdmin\Controller;

use SunAdmin\Common\ResponseJson;
use SunAdmin\Service\DataDictionaryService;

class DataDictionaryController
{

    public function getCateTreeList(){
        $treeList = DataDictionaryService::getCateTreeList();
        return ResponseJson::success(['treeList'=>$treeList]);
    }

    public function edit(){
        $data = request()->param();
        if (!request()->adminUser->is_administrators) {
            return ResponseJson::error("仅允许超级管理员操作");
        }
        DataDictionaryService::edit($data);
        return ResponseJson::success();
    }

    public function delete($id){
        if (!request()->adminUser->is_administrators) {
            return ResponseJson::error("仅允许超级管理员操作");
        }
        DataDictionaryService::del($id);
        return ResponseJson::success();
    }

    /**
     * 获取类目下配置数据列表
     */
    public function getCateInnerDataList($cateId){
        $res = DataDictionaryService::getCateInnerDataList($cateId);
        return ResponseJson::success(['list'=>$res]);
    }
}